#include "imagegetimageresponse.h"

// Qt includes
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QPixmap>

namespace Network {

/**
 * @brief GetImageResponse::GetImageResponse
 * @param parent
 */
GetImageResponse::GetImageResponse(QObject *parent) :
    Network::Response(parent),
    m_redirected(false)
{
}

//-----------------------------------------------------------------------------------
GetImageResponse::~GetImageResponse()
{

}

//-----------------------------------------------------------------------------------
bool GetImageResponse::isRedirected() const
{
    return m_redirected;
}

//-----------------------------------------------------------------------------------
void GetImageResponse::parse(QNetworkReply &reply)
{
    QNetworkReply::NetworkError error = reply.error();
    if (error != QNetworkReply::NoError) {
        setError(Network, reply.errorString());
        return;
    }
    QByteArray data = reply.readAll();
    parse(data);
}

void GetImageResponse::parse(const QByteArray &data)
{
    m_image.loadFromData(data);
}

//-----------------------------------------------------------------------------------
const QImage &GetImageResponse::image() const
{
    return  m_image;
}

} // namespace Network
